﻿using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
using OxyPlot.Series;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MyWpfControls.Pages.OxyPlot
{
    /// <summary>
    /// Bar1.xaml 的交互逻辑
    /// </summary>
    public partial class Bar1 : Page
    {
        public Bar1()
        {
            InitializeComponent();

            this.Model0 = CreatePlotModel(0, 10);

            this.DataContext = this;
        }

        public PlotModel Model0 { get; private set; }

        private static PlotModel CreatePlotModel(double min, double max)
        {
            bool flag = true;
            double val = 0;

            var model = new PlotModel();

            model.PlotAreaBorderColor = OxyColor.FromArgb(100, 30, 30, 30);

            model.Axes.Add(new LinearAxis()
            {
                MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139),
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139),
                MinorGridlineStyle = LineStyle.Dot,
                TicklineColor = OxyColor.FromArgb(100, 30, 30, 30),
                MaximumPadding = 0.5,
                MinimumPadding = 0.5,
                IsZoomEnabled = false,
                IsPanEnabled = false,
            });

            model.Axes.Add(new LinearAxis()
            {
                MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139),
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139),
                MinorGridlineStyle = LineStyle.Dot,
                Position = AxisPosition.Bottom,
                TicklineColor = OxyColor.FromArgb(100, 30, 30, 30),
                IsZoomEnabled = false,
                IsPanEnabled = false,
            });

            var lineSeries = new LinearBarSeries()
            {
                BarWidth = 30,
            };

            for (int i = 0; i < 1000; i += 50)
            {
                if (val == 10)
                {
                    flag = false;
                }
                if (val == 0)
                {
                    flag = true;
                }
                lineSeries.Points.Add(new DataPoint(i, val));

                model.Annotations.Add(new TextAnnotation()
                {
                    Text = val + "",
                    TextPosition = new DataPoint(i, val),
                    StrokeThickness = 0
                });

                val += flag ? 1 : -1;
            }


            model.Series.Add(lineSeries);
            return model;
        }
    }
}
